package com.homework.ch11;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/15
 * @Description:
 */
public class Test027_MultipleCopy {
    public static void main(String[] args) throws IOException {
        String dirPath = "D:/test";
        String fileName = "img.jpg";
        int number = 10;

        File file = new File(dirPath, fileName);
        if (!file.exists()) {
            System.out.println("源文件不存在: " + file.getAbsolutePath());
            return;
        }

        for (int i = 1; i < 11; i++) {
            String destFileName = "img_copy" + i + ".jpg";
            InputStream is = new FileInputStream(file);
            OutputStream os = new FileOutputStream(new File(dirPath, destFileName));
            byte[] arr = new byte[1024];
            int len = 0;
            while ((len = is.read(arr)) != -1) {
                os.write(arr, 0, len);
            }
            File file1=new File(dirPath,destFileName);
            System.out.println("第" + i + "份复制完成: " + file1.getAbsolutePath());
            os.close();
            is.close();
        }
    }
}
